<?php
namespace Admin\Controller;
use Think\Controller;



class IndexController extends CommonController {
    	public function index()
    	{
    		$this->display();
    	}

    	//统计数据库表中的数据
    	public function countData()
    	{
    		$str = date('y-m-d');
    		//今天
    		$time = strtotime($str);
    		//昨天
    		$yesterday = strtotime('-1 days',$time);
    		//一周之内
    		$week = strtotime('-7 days',$time);
    		//一个月之类
    		$mouth = strtotime('-30 days',$time);
    		$data = array();

    		$sql = "select count(id) cn from question";

    		$data['总数'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from user";

    		$data['总数'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from answer";

    		$data['总数'][]=M()->query($sql)[0]['cn'];
    		//一天之内
    		$sql = "select count(id) cn from question where create_time>{$time}";

			$data['今天'][]=M()->query($sql)[0]['cn'];

			$sql = "select count(id) cn from user where create_time>{$time}";

			$data['今天'][]=M()->query($sql)[0]['cn'];


			$sql = "select count(id) cn from answer where create_time>{$time}";

			$data['今天'][]=M()->query($sql)[0]['cn'];


    		$sql = "select count(id) cn from question where create_time<{$time} and create_time>{$yesterday}";

    		$data['昨天'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from user where create_time<{$time} and create_time>{$yesterday}";

    		$data['昨天'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from answer where create_time<{$time} and create_time>{$yesterday}";

    		$data['昨天'][]=M()->query($sql)[0]['cn'];
    		
    		$sql = "select count(id) cn from question where create_time>{$week}";

    		$data['一周'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from user where create_time>{$week}";

    		$data['一周'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from answer where create_time>{$week}";

    		$data['一周'][]=M()->query($sql)[0]['cn'];
    		
    		$sql = "select count(id) cn from question where create_time>{$mouth}";
    		
    		$data['一月'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from user where create_time>{$mouth}";
    		
    		$data['一月'][]=M()->query($sql)[0]['cn'];

    		$sql = "select count(id) cn from answer where create_time>{$mouth}";
    		
    		$data['一月'][]=M()->query($sql)[0]['cn'];
    		// var_dump($data);

    		return $data;

    	}
    	public function welcome()
    	{
    		if (S('welcomData')) {
    			
    			$data = S('welcomData');
    		}else{
    			$data = $this->countData();
    			S('welcomData',$data);
    			
    		}
    		$this->assign('data',$data);

    		$this->display();
    	}
    	

        //图标数据
        public function getData()
        {   
            $arr = array(
            array(
                'value'=>300,
                'name'=>'北京'
                ),
            array(
                'value'=>400,
                'name'=>'广州'
                ),
            array(
                'value'=>300,
                'name'=>'深圳'
                ),
            array(
                'value'=>450,
                'name'=>'上海'
                )
            );

        echo json_encode($arr);
        }
        


   }
?>